﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	StatisticByIncome
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">    
    <h2>StatisticByIncome</h2>
    <script type="text/javascript">
        function TypeChange(a) {
            
            if (a != '0') {
                type = a;
            } else {
                type = $("#slType").val();
            }
            
            if (type == "Thang") {
                $("#divslThang").slideDown();
                $("#divslQuy").slideUp();
            }
            else if (type == "Quy") {
                $("#divslQuy").slideDown();
                $("#divslThang").slideUp();
            }
            else {
                $("#divslQuy").slideUp();
                $("#divslThang").slideUp();
            }
        }
    </script>
    <%using (Html.BeginForm())
      { %>
      Thống kê theo: 
    <select id="slType" name="type" onchange="javascript:TypeChange('0')">
    <%if (Convert.ToInt32(ViewData["Type"].ToString()) == 1)
      {%>
          <option selected=selected value="Thang">Tháng</option>
          <option value="Quy">Quý</option>
          <option value="Nam">Năm</option>          
      <%}
      else if (Convert.ToInt32(ViewData["Type"].ToString()) == 2)
      {%>
          <option value="Thang">Tháng</option>
          <option selected=selected value="Quy">Quý</option>
          <option value="Nam">Năm</option>
      <%}
      else
      {%>
          <option value="Thang">Tháng</option>
          <option value="Quy">Quý</option>
          <option selected=selected value="Nam">Năm</option>
      <%} %>                    
    </select>
    
    <div id="selectTime">
        <div id="divslThang">
        Chọn Tháng:
        <select id="slThang" name="thang">
            <%for (int i = 1; i <= 12; i++)
              {
                  if (i == Convert.ToInt32(ViewData["Thang"].ToString()))
                  {%>
                      <option selected=selected value="<%:i %>"><%: i%></option>
                  <%}
                  else
                  {%>
                      <option value="<%:i %>"><%: i%></option>
                  <%}%>                  
            <%} %>            
        </select>
        </div>
        <div id="divslQuy" style="display:none">
        Chọn Quý:
        <select id="slQuy" name="quy">
            <%for (int i = 1; i <= 4; i++)
              {
                  if (i == Convert.ToInt32(ViewData["Quy"].ToString()))
                  {%>
                      <option selected=selected value="<%:i %>"><%: i%></option>
                  <%}
                  else
                  {%>
                      <option value="<%:i %>"><%: i%></option>
                  <%}%> 
            <%} %>
        </select>
        </div>
        <div id="divslNam">
        Chọn Năm:
        <select id="slNam" name="nam">
            <%for (int i = 1989; i <= 2030; i++)
              {
                  if (i == Convert.ToInt32(ViewData["Nam"].ToString()))
                  {%>
                      <option selected=selected value="<%:i %>"><%: i%></option>
                  <%}
                  else
                  {%>
                      <option value="<%:i %>"><%: i%></option>
                  <%}%>                  
            <%} %>
        </select>
        </div>
        
    </div>
    <%if (Convert.ToInt32(ViewData["Type"].ToString()) == 1)
      {%>
          <script type="text/javascript">
              TypeChange('Thang');
          </script>
      <%}
      else if (Convert.ToInt32(ViewData["Type"].ToString()) == 2)
      {%>
          <script type="text/javascript">
              TypeChange('Quy');
          </script>
      <%}
      else
      {%>
          <script type="text/javascript">
              TypeChange('Nam');
          </script>
      <%} %>
    <input type="submit" value="Thống Kê"/>
    <%} %>
    <div>
        Tổng số lượng giao dịch: <%: ViewData["SoLuong"] %>
    </div>
    <div>
        Doanh thu: <%: ViewData["DoanhThu"] %>
    </div>
    <div>
        Doanh Nghiệp có Doanh Thu cao nhất: <%: ViewData["DoanhNghiep"] %>
    </div>
    <div id="placeholder" style="width:600px;height:300px"></div>
    <p id="hoverdata"></p>
    <script type="text/javascript">
        var plot;
        $(function () {
            var sin = [], cos = [];
            for (var i = 0; i < 14; i += 0.1) {
                sin.push([i, Math.sin(i)]);
                cos.push([i, Math.cos(i)]);
            }

            plot = $.plot($("#placeholder"),
                      [{ data: sin, label: "sin(x) = -0.00" },
                        { data: cos, label: "cos(x) = -0.00"}], {
                            series: {
                                lines: { show: true }
                            },
                            crosshair: { mode: "x" },
                            grid: { hoverable: true, autoHighlight: false },
                            yaxis: { min: -1.2, max: 1.2 }
                        });
            var legends = $("#placeholder .legendLabel");
            legends.each(function () {
                // fix the widths so they don't jump around
                $(this).css('width', $(this).width());
            });

            var updateLegendTimeout = null;
            var latestPosition = null;

            function updateLegend() {
                updateLegendTimeout = null;

                var pos = latestPosition;

                var axes = plot.getAxes();
                if (pos.x < axes.xaxis.min || pos.x > axes.xaxis.max ||
            pos.y < axes.yaxis.min || pos.y > axes.yaxis.max)
                    return;

                var i, j, dataset = plot.getData();
                for (i = 0; i < dataset.length; ++i) {
                    var series = dataset[i];

                    // find the nearest points, x-wise
                    for (j = 0; j < series.data.length; ++j)
                        if (series.data[j][0] > pos.x)
                            break;

                    // now interpolate
                    var y, p1 = series.data[j - 1], p2 = series.data[j];
                    if (p1 == null)
                        y = p2[1];
                    else if (p2 == null)
                        y = p1[1];
                    else
                        y = p1[1] + (p2[1] - p1[1]) * (pos.x - p1[0]) / (p2[0] - p1[0]);

                    legends.eq(i).text(series.label.replace(/=.*/, "= " + y.toFixed(2)));
                }
            }

            $("#placeholder").bind("plothover", function (event, pos, item) {
                latestPosition = pos;
                if (!updateLegendTimeout)
                    updateLegendTimeout = setTimeout(updateLegend, 50);
            });
        });
    </script>

</asp:Content>
